package com.bage.finance.admin.api.controller;

import com.bage.common.dto.ApiResponse;
import com.bage.finance.biz.dto.form.GetBase64CodeForm;
import com.bage.finance.biz.dto.form.GetSmsCodeForm;
import com.bage.finance.biz.service.MemberLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "用户登录模块")
@RestController
@RequestMapping(value = "/login")
@RequiredArgsConstructor // 自动注入
@Slf4j
public class LoginController {
    final MemberLoginService memberLoginService;


    /**
     * 获取客户端ID
     *
     * @return
     */
    @ApiOperation("获取客户端ID") //@ApiOperation注解描述一个方法接口功能
    @GetMapping(value = "/getClientId")
    public ApiResponse<String> getClientId() {
        String result = memberLoginService.getClientId();
        return ApiResponse.success(result);
    }

    /**
     * 获取图形验证码
     *
     * @return
     */
    @ApiOperation("获取图形验证码")
    @GetMapping(value = "/getBase64Code")
    //@Validated:用于激活验证功能
    //@ModelAttribute:用于接收参数(数据来源: URL 参数、请求头、表单字段)
    //@RequestBody:用于接收参数(数据来源: 请求体):将Json数据转换成对象
    public ApiResponse<String> getBase64Code(@Validated @ModelAttribute GetBase64CodeForm form){
        String code  = memberLoginService.getBase64Code(form);
        return ApiResponse.success(code);
    }


    /**
     * 获取短信验证码
     * @param form
     * @return
     */
    @ApiOperation(value = "获取短信验证码")
    @GetMapping(value = "/sendSmsCode")
    public ApiResponse<Void> sendSmsCode(@Validated @ModelAttribute GetSmsCodeForm form) {
        memberLoginService.sendSmsCode(form);
        return ApiResponse.success();
    }


}
